package com.ss.android.article.base.utils.searchtext;

import android.text.TextUtils;

import com.bytedance.retrofit2.Callback;
import com.bytedance.retrofit2.ResponseWrapper;

import org.json.JSONException;
import org.json.JSONObject;

public final class SearchHintCallback implements Callback {
    private final String a;
    private final String b;
    private final SearchTextHelper.OnSearchTextRefreshListener mOnSearchTextRefreshListener;

    public SearchHintCallback(String arg1, String arg2, SearchTextHelper.OnSearchTextRefreshListener onSearchTextRefreshListener) {
        this.a = arg1;
        this.b = arg2;
        this.mOnSearchTextRefreshListener = onSearchTextRefreshListener;

    }

    public final void onCacheResponse(ResponseWrapper response) {
        JSONObject jo;
        try {
            jo = new JSONObject((String) response.body);
        } catch (JSONException jsonException) {
            return;
        }

        String homePageSearchSuggest = "";
        String message = jo.optString("message");
        if (!TextUtils.isEmpty(message) && (message.equals("success"))) {
            jo = jo.optJSONObject("data");
            if (jo != null) {
                homePageSearchSuggest = jo.optString("homepage_search_suggest");
            }
        }
        if (!TextUtils.isEmpty(((CharSequence) homePageSearchSuggest))) {
            SearchTextData searchTextData = new SearchTextData();
            searchTextData.homePageSearchSuggest = homePageSearchSuggest;
            searchTextData.b = this.a;
            searchTextData.c = this.b;
            if (this.mOnSearchTextRefreshListener != null) {
                this.mOnSearchTextRefreshListener.onSearchTextRefresh(searchTextData);
            }
        }
    }

    public final void onErrorResponse(Throwable throwable) {
    }
}

